//
//  HOCaiyunUser.m
//  EQC
//
//  Created by foguo-mac-1 on 02/11/2017.
//  Copyright © 2017 WeiDu. All rights reserved.
//

#import "HOCaiyunUser.h"
#import "HOConstants.h"

@implementation HOCaiyunUser
- (instancetype)init
{
	if(self = [super init])
	{
		[self readFromLocal];
	}
	return self;
}

- (void)parseDic:(NSDictionary *)dic
{	
	self.name = [dic objectForKey:kCY_FIELD_Name];
	self.orgId = [dic objectForKey:kCY_FIELD_OrgId];
	self.orgSecret = [dic objectForKey:kCY_FIELD_OrgSecret];
	self.uid = [dic objectForKey:kCY_FIELD_Uid];
}

- (void)readFromLocal
{
	NSUserDefaults *userData = [NSUserDefaults standardUserDefaults];
	self.name = [userData objectForKey:kCY_FIELD_Name];
	self.orgId = [userData objectForKey:kCY_FIELD_OrgId];
	self.orgSecret = [userData objectForKey:kCY_FIELD_OrgSecret];
	self.uid = [userData objectForKey:kCY_FIELD_Uid];
}

- (BOOL)isValueValidated
{
	if(self.name == nil)
		return NO;
	if(self.orgId == nil)
		return NO;
	if(self.orgSecret == nil)
		return NO;
	if(self.uid == nil)
		return NO;
	return YES;
}

- (void)saveIntoLocal
{
	NSUserDefaults *userData = [NSUserDefaults standardUserDefaults];
	[userData setObject:self.name forKey:kCY_FIELD_Name];
	[userData setObject:self.orgSecret forKey:kCY_FIELD_OrgSecret];
	[userData setObject:self.uid forKey:kCY_FIELD_Uid];
	[userData setObject:self.orgId forKey:kCY_FIELD_OrgId];
	[userData synchronize];
}
@end
